package com.gz.controller;

import com.gz.entity.Answers;
import com.gz.entity.Tuser;
import com.gz.service.AnswersService;
import com.gz.vo.AnswerRes;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.gz.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.gz.dto.AnswersDto;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 用户答题表(Answers)表控制层
 *
 * @author makejava
 * @since 2024-05-27 15:08:56
 */
@RestController
@RequestMapping("answers")
@Api(value = "用户答题卡控制层", tags = {"用户答题卡控制层"})
public class AnswersController {
    /**
     * 服务对象
     */
    @Autowired
    private AnswersService answersService;

    /**
     * 分页查询
     *
     * @param dto 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/queryPage")
    public R queryByPage(@RequestBody AnswersDto dto, HttpServletRequest request) {
        return R.ok(answersService.queryByPage(dto));
    }

    /**
     * 分页查询
     *
     * @param dto 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "条件查询")
    @PostMapping("/queryAll")
    public R queryAll(@RequestBody AnswersDto dto, HttpServletRequest request) {
        return R.ok(answersService.queryAll(dto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "主键查询")
    @GetMapping("/queryById")
    public R<Answers> queryById(@RequestParam("id") Integer id) {
        return R.ok(answersService.queryById(id));
    }
    /**
     * 通过主键查询答题结果
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "主键查询用户答题详情集合题目答案")
    @GetMapping("/queryAnswerResById")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = AnswerRes.class),
    })
    public R<?> queryAnswerResById(@RequestParam("id") Integer id) {
        return R.ok(answersService.queryAnswerResById(id));
    }

    /**
     * 新增数据
     *
     * @param answers 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @PostMapping("/save")
    public R<Answers> add(@RequestBody Answers answers) {
        return R.ok(answersService.insert(answers));
    }

    /**
     * 新增数据
     *
     * @param batchData 集合
     * @return 新增结果
     */
    @ApiOperation(value = "批量新增数据")
    @PostMapping("/saveBatch")
    public R<Integer> addBatch(@RequestBody List<Answers> batchData) {
        return R.ok(answersService.insertBatch(batchData));
    }

    /**
     * 编辑数据
     *
     * @param answers 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "编辑数据")
    @PostMapping("/update")
    public R<Answers> edit(@RequestBody Answers answers) {
        return R.ok(answersService.update(answers));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/deleteById")
    @ApiOperation(value = "删除数据")
    public R<Boolean> deleteById(@RequestParam("id") Integer id) {
        return R.ok(answersService.deleteById(id));
    }

}

